<template>
  <div class="aui-page__gateway" style="hight:400px">
    正在准备办理数据...
  </div>
</template>

<script>
import { isEmpty } from '@/utils/validate'
import mixinViewModule from '@/mixins/view-module'
import content from '@/views/main-content'

export default {
  mixins: [mixinViewModule],
  data () {
    return {
      url: `/flowable/task/${this.$route.params.id}`
    }
  },
  created () {
  },
  mounted () {
    this.$http.get(this.url).then(({ data: res }) => {
      if (res.code !== 0) {
        return this.$message.error(res.msg)
      }
      if (res.data) {
        this.deal(res.data)
      } else {
        return this.$message.error('未获取到任务！')
      }
    }).catch(() => { })
  },
  methods: {
    deal (task) {
      this.$nextTick(() => {
        this.$http.get(`flowable/bpmFormUrl/form/${task.formId}`).then(({ data: res }) => {
          if (res.code !== 0) {
            return
          }
          if (isEmpty(res.data.pc.url)) {
            return this.$message.error('流程对应的表单没有定义')
          }
          this.openFlow(task, res.data.pc.url)
        }).catch(() => { })
      })
    },
    openFlow (task, url) {
      this.$http.post('/flowable/bpmTaskExt/getByTaskDefId', {
        taskDefId: task.key,
        processInstId: task.procDefId
      }).then(({ data: res }) => {
        if (res.code !== 0) {
          return
        }
        // 添加子级路由
        var router = {
          name: 'flowable-todo-manage-deal',
          id: task.procInstId,
          menuId: this.$route.meta.menuId,
          oldName: 'flowable-todo-parent',
          path: 'flowable/todo-manage-deal',
          title: task.processName + '---' + this.$t('approveManage.deal')
        }
        var params = {
          task: task,
          edit: false,
          formId: task.formId,
          bizId: task.bizId,
          url: url,
          formData: res.data.formDTO
        }
        console.log('设置定时关闭tab')
        let closeTab = this.$route.name
        setTimeout(() => {
          content.methods.tabRemoveHandle(closeTab)
        }, 1000)
        this.$options.methods.openNewTab(this.$router, router, params, true)
      }).catch(() => {
      })
    }
  }
}
</script>

<style>
.approve-manage .el-card__body {
  padding: 20px 10px 0px 20px;
}
</style>
